<?php
namespace Adminx\Controller;

class ItemController extends AdminController {

	#列表
	public function index() {
		$cate = I('get.cate');
		$map['id'] = $cate;
		$list = M('OptionCate')->where($map)->find();
		if ($list) {
			unset($map);
			$map['cate'] = $cate;
			$cate = M('OptionItem')->where($map)->select();	
			$this->assign('list',$list);
			$this->assign('cate',$cate);
			$this->display();
		}else{
			$this->error('字段不存在');
		}		
	}

	#添加
	public function add() {
		if($_POST){
			$this->all_add('OptionItem');
		}else{
			$cate = I('get.id');
			$this->assign('cate',$cate);
			$this->display();
		}		
	}

	#编辑
	public function edit() {
		if($_POST){
			$this->all_save('OptionItem');
		}else{
			$id = (int) $_GET['id'];
			if (!isset ($id)) {
				$this->error('参数错误');
			}
			$obj = M('OptionItem');
			$map['id']=$id;
			$list = $obj->where($map)->find();
			if (!$list) {
				$this->error('信息不存在');
			} else {
				$this->assign('list', $list);
				$this->display();
			}
		}		
	}

	#删除
	public function del() {
		$this->all_del('OptionItem','reload');
	}
}
?>